<template>
    <mi-form-page @submit="submit"
                  :loading="edit.loading"
                  v-model:show="edit.show"
                  title="支付配置"
    >
        <el-form :model="edit.info"
                 :rules="rules"
                 :label-width="180"
                 ref="formRef">

            <el-tabs model-value="wx">

                <el-tab-pane label="微信支付" name="wx">

                    <el-form-item prop="is_on" label="开启微信支付">
                        <mi-radio v-model="edit.info.value.wx.is_on"/>
                    </el-form-item>

                    <el-form-item prop="is_te" label="特约商户">
                        <mi-radio v-model="edit.info.value.wx.is_te"/>
                    </el-form-item>

                    <template v-if="edit.info.value.wx.is_te == 1">
                        <el-form-item prop="te_appid" label="服务商te_appid">
                            <mi-input v-model="edit.info.value.wx.te_appid"/>
                        </el-form-item>
                        <el-form-item prop="te_mchid" label="服务商te_mchid">
                            <mi-input v-model="edit.info.value.wx.te_mchid"/>
                        </el-form-item>
                        <el-form-item prop="te_sub_mchid" label="特约商户号te_sub_mchid">
                            <mi-input v-model="edit.info.value.wx.te_sub_mchid"/>
                        </el-form-item>
                        <el-form-item prop="te_v3key" label="te_v3key">
                            <mi-input v-model="edit.info.value.wx.te_v3key"/>
                        </el-form-item>
                        <el-form-item prop="te_cert_path" label="平台证书te_cert_path">
                            <mi-up-file v-model="edit.info.value.wx.te_cert_path" :params="{disk:'local'}"/>
                        </el-form-item>
                        <el-form-item prop="te_key_path" label="商户api私钥te_key_path">
                            <mi-up-file v-model="edit.info.value.wx.te_key_path" :params="{disk:'local'}"/>
                        </el-form-item>
                        <el-form-item prop="te_v3_platform_cert_path" label="te_v3_platform_cert_path">
                            <mi-up-file v-model="edit.info.value.wx.te_platform_cert_path"
                                        :params="{disk:'local'}"/>
                            <div class="f_secondary">微信支付平台证书（v3）</div>
                        </el-form-item>
                        <el-form-item prop="te_v3_mch_serial" label="te_v3_mch_serial">
                            <mi-input v-model="edit.info.value.wx.te_mch_serial"/>
                            <div class="f_secondary">api证书序列号（v3）</div>
                        </el-form-item>
                    </template>

                    <template v-else>
                        <el-form-item prop="mchid" label="商户号mchid">
                            <mi-input v-model="edit.info.value.wx.mchid"/>
                        </el-form-item>
                        <el-form-item prop="v3key" label="v3key">
                            <mi-input v-model="edit.info.value.wx.v3key"/>
                        </el-form-item>
                        <el-form-item prop="cert_path" label="平台证书cert_path">
                            <mi-up-file v-model="edit.info.value.wx.cert_path" :params="{disk:'local'}"/>
                        </el-form-item>
                        <el-form-item prop="key_path" label="商户api私钥key_path">
                            <mi-up-file v-model="edit.info.value.wx.key_path" :params="{disk:'local'}"/>
                        </el-form-item>
                        <el-form-item prop="te_platform_cert_path" label="te_platform_cert_path">
                            <mi-up-file v-model="edit.info.value.wx.platform_cert_path"
                                        :params="{disk:'local'}"/>
                            <div class="f_secondary">微信支付平台证书（v3）</div>
                        </el-form-item>
                        <el-form-item prop="te_mch_serial" label="te_mch_serial">
                            <mi-input v-model="edit.info.value.wx.mch_serial"/>
                            <div class="f_secondary">api证书序列号（v3）</div>
                        </el-form-item>
                    </template>

                </el-tab-pane>

                <el-tab-pane label="支付宝支付" name="ali">
                    <el-form-item prop="is_on" label="开启支付宝支付">
                        <mi-radio v-model="edit.info.value.ali.is_on"/>
                    </el-form-item>
                </el-tab-pane>


                <el-tab-pane label="余额支付" name="balance">
                    <el-form-item prop="is_on" label="开启余额支付">
                        <mi-radio v-model="edit.info.value.balance.is_on"/>
                    </el-form-item>
                </el-tab-pane>


            </el-tabs>

        </el-form>
    </mi-form-page>
</template>

<script setup lang="ts">
import {reactive, watch, ref, onBeforeMount, inject, computed} from "vue";
import {simpleGet, simplePost} from "@/utils/request";
import {FormInstance} from "element-plus";
import Edit from "@/model/edit";

const url = '/site.siteConfig/edit'

const rules = {

}

const loading = ref(false)
const formRef = ref<FormInstance>()
const parentOptions = ref<any[]>([])
const edit = inject('paySet', new Edit({}))
edit.info = {
    value:{
        wx:{},
        ali:{},
        balance:{},
    }
}


const submit = () => {
    edit.submit({
        formRef: formRef.value,
        url: url,
    })
}

watch(() => edit.show, (nv,ov) => {
    edit.init(async () => {
        let {info} = await simpleGet(url, {key:'pay_set'})
        edit.info = info
    })
})


</script>

<style scoped>

</style>

